﻿package 
{
	import com.adobe.serialization.json.JSON;
	import com.athena.utils.AthenaUtils;
	import com.cubeia.firebase.connector.FirebaseClient;
	import com.cubeia.firebase.events.ConnectEvent;
	import com.cubeia.firebase.events.DisconnectEvent;
	import com.cubeia.firebase.events.GamePacketEvent;
	import com.cubeia.firebase.events.LobbyEvent;
	import com.cubeia.firebase.events.LoginResponseEvent;
	import com.cubeia.firebase.events.PacketEvent;
	import com.cubeia.firebase.io.ProtocolObject;
	import com.cubeia.firebase.io.protocol.CreateTableResponsePacket;
	import com.cubeia.firebase.io.protocol.ForcedLogoutPacket;
	import com.cubeia.firebase.io.protocol.GameTransportPacket;
	import com.cubeia.firebase.io.protocol.JoinRequestPacket;
	import com.cubeia.firebase.io.protocol.JoinResponsePacket;
	import com.cubeia.firebase.io.protocol.LeaveResponsePacket;
	import com.cubeia.firebase.io.protocol.LoginRequestPacket;
	import com.cubeia.firebase.io.protocol.ServiceTransportPacket;
	import com.cubeia.firebase.io.protocol.TableUpdatePacket;
	import com.cubeia.firebase.model.LobbyDataItem;
	
	import flash.display.*;
	import flash.display.MovieClip;
	import flash.errors.*;
	import flash.events.*;
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.XMLSocket;
	import flash.utils.*;
	import flash.utils.ByteArray;
	import com.athena.process.*;
	import com.athena.process.ProcessInTable;
	import com.athena.process.ProcessOutTable_Frame2;
	import com.athena.process.ProcessOutTable_Frame1;
	import com.junkbyte.console.Cc;
	
	public class CustomSocket extends FirebaseClient{
		private var _response:String;		
		public function CustomSocket(host:String = null, port:String = null) {
			addEventListener(ConnectEvent.CONNECT, onFirebaseConnect);
			addEventListener(DisconnectEvent.DISCONNECT, onFirebaseDisconnect);
			addEventListener(LoginResponseEvent.LOGIN, onFirebaseLogin);
			addEventListener(PacketEvent.PACKET_RECEIVED, onPacketReceived);
			addEventListener(GamePacketEvent.PACKET_RECEIVED, onGamePacketReceived);
			open(host, port);			
		}
		
		public function addLobby():void {
			addEventListener(LobbyEvent.TABLE_ADDED, onTableAdded);
			addEventListener(LobbyEvent.TABLE_UPDATED, onTableUpdated);
			addEventListener(LobbyEvent.TABLE_REMOVED, onTableRemoved);
			
			Cocaro.oldaddressLobby = Cocaro.newaddressLobby;
			Cocaro.newaddressLobby = Cocaro.levelID + "/" + Cocaro.roomID + "/";
			if(Cocaro.oldaddressLobby.length>0)
				lobbyUnsubscribe(Cocaro.GAME_ID, Cocaro.oldaddressLobby);
			lobbySubscribe(Cocaro.GAME_ID, Cocaro.newaddressLobby);
		}
		public function removeLobby():void {
			lobbyUnsubscribe(Cocaro.GAME_ID, Cocaro.newaddressLobby);
			removeEventListener(LobbyEvent.TABLE_ADDED,onTableAdded);
			removeEventListener(LobbyEvent.TABLE_UPDATED,onTableUpdated);
			removeEventListener(LobbyEvent.TABLE_REMOVED,onTableRemoved);
		}
		
		public function sendData(str:String) {
			var data:ByteArray = new ByteArray();
			data.writeUTFBytes(str);
			var gameTransportPacket:GameTransportPacket = new GameTransportPacket();
			gameTransportPacket.pid = Cocaro.currPlayer.pid;
			gameTransportPacket.tableid =  Cocaro.tableID;
			gameTransportPacket.gamedata = data;
			send(gameTransportPacket);
		}
		
		public function sendService(str:String) {
			var servicePacket:ServiceTransportPacket = new ServiceTransportPacket();
			servicePacket.idtype = 1;
			servicePacket.pid = Cocaro.currPlayer.pid;
			servicePacket.seq = 1;
			servicePacket.service = "com.athena.services.api.ServiceContract";
			var data:ByteArray = new ByteArray();
			data.writeUTFBytes(str);
			servicePacket.servicedata = data;
			send(servicePacket);
		}
		private function onFirebaseConnect(connectEvent:ConnectEvent):void
		{
			removeEventListener(ConnectEvent.CONNECT, onFirebaseConnect);
			var obUser:Object = new Object();
			obUser.Userid = Cocaro.user.UserId;
			obUser.Username = Cocaro.user.Username;
			obUser.From = Cocaro.user.From;
			obUser.gameid = Cocaro.GAME_ID;
			login(JSON.encode(obUser), Cocaro.user.SessionId ,105);
		}
		
		private function onFirebaseDisconnect(disconnectEvent:DisconnectEvent):void
		{
			BasicFunction.ShowAlert("Bạn bị đứt kết nối với máy chủ") ;
			//Cocaro.tf.appendText("\r\n onFirebaseDisconnect....");
		}
		private function onFirebaseLogin(loginEvent:LoginResponseEvent):void
		{
			try {
				if (loginEvent.getPlayerInfo().code == 0) {
					
					Cocaro.currPlayer.pid = loginEvent.getPlayerInfo().pid;
					var ob:Object = new Object();
					ob.evt = "1";
					ob.gameid = Cocaro.GAME_ID;
					sendService(JSON.encode(ob));
				} else if (loginEvent.getPlayerInfo().code == -1) {
					BasicFunction.ShowAlert("Tài khoản đang được sử dụng !");
				} else if (loginEvent.getPlayerInfo().code == -2) {
					BasicFunction.ShowAlert("Bạn cần đăng nhập lại Me Zing !");
				} else if (loginEvent.getPlayerInfo().code == -3) {
					BasicFunction.ShowAlert("Tài khoản chưa được khởi tạo !");
				} else if (loginEvent.getPlayerInfo().code == -4) {
					BasicFunction.ShowAlert("Tài khoản bạn đang bị hệ thống khóa, liên hệ với Admin để được trợ giúp!");
				} else {
					BasicFunction.ShowAlert("Kết nối máy chủ gặp vấn đề !");
				} 
			} catch (e:Error ) {
			   //Cocaro.tf.appendText("\r\n Error:"+e.getStackTrace());
			}
		}
		
		private function onPacketReceived(packetEvent:PacketEvent):void
		{
			var protocolObject:ProtocolObject = packetEvent.getObject();
			switch ( protocolObject.classId() ) {
				case JoinResponsePacket.CLASSID:
					handleJoinResponsePacket(JoinResponsePacket(protocolObject));
					break;
				case ServiceTransportPacket.CLASSID:
					handleServiceTransportPacket(ServiceTransportPacket(protocolObject));
					break;
				case CreateTableResponsePacket.CLASSID:
					handleCreateTableResponsePacket(CreateTableResponsePacket(protocolObject));
					break;
				case LeaveResponsePacket.CLASSID:
					Cocaro.tableID = 0;
					Cocaro.PARAM_CREATE_TABLE = new Array();
					break;
				default:
					break;
			}
		}
		
		public function onGamePacketReceived(gamePacketEvent:GamePacketEvent):void {
			var data:ByteArray = gamePacketEvent.getPacketData();
			var bytes:int = data.bytesAvailable;
			if (bytes == 0){
				return;
			}
			var msg:String = data.readUTFBytes(bytes);
			Cc.log(msg);
			var objReceive:Object = JSON.decode(msg);
			if (objReceive.evt == "ctable") {
				removeLobby();
				ProcessInTable.CreateTable(JSON.decode(objReceive.data));
			}else if (objReceive.evt == "stable") { //Join Table
				if ((Cocaro.mainStage_mc.currentFrame == 5) || (Cocaro.mainStage_mc.currentFrame == 4)) {
					//unRegistryLobby();
					removeLobby();
					ProcessInTable.JoinTable(JSON.decode(objReceive.data));
				}
			} else if (objReceive.evt == "jtable") { //Other Join Table
				if (Cocaro.mainStage_mc.currentFrame == 5) {
					ProcessInTable.OtherJoinTable(JSON.decode(objReceive.data)) ;
				}
			} else if (objReceive.evt == "rtable") { //Player khac gui thong bao san sang
				if (Cocaro.mainStage_mc.currentFrame == 5) {
					ProcessInTable.ReadyTable(objReceive);
				}
			} else if (objReceive.evt == "ltable") { 
				if (Cocaro.mainStage_mc.currentFrame == 5) {
					ProcessInTable.ExitTable(objReceive.Name);
				}
			} else if (objReceive.evt == "cctable") { //view table
				if (Cocaro.mainStage_mc.currentFrame == 5) {
					ProcessInTable.ChangeTable(objReceive.Name) ;
				}
			} else if (objReceive.evt == "vtable") { //view table
				//if (mainStage_mc.currentFrame == 4)
					//ViewTable(obj) ;
			} else if (objReceive.evt == "sgame") { //Khoi tao ban choi
				if (Cocaro.mainStage_mc.currentFrame == 5) {
					ProcessInTable.InitGame(objReceive.Name);
				}
			} else if (objReceive.evt == "playchess") {
				if (Cocaro.mainStage_mc.currentFrame == 5)
					ProcessInTable.caroOtherPlay(objReceive);
			} else if (objReceive.evt == "commandsend") {
				if (Cocaro.mainStage_mc.currentFrame == 5) {
					if(objReceive.event == "warning")
						ProcessInTable.Warning(objReceive.Name);
					else if (objReceive.event == "chieutuong")
						ProcessInTable.ChieuTuong(objReceive.Name) ;
					else if (objReceive.event == "cauhoa")
						ProcessInTable.Other_Cauhoa(objReceive.Name) ;
					else if (objReceive.event == "dilai")
						ProcessInTable.Other_Xindilai(objReceive.Name) ;
					else if (objReceive.event == "khongcauhoa")
						ProcessInTable.Other_KhongCauhoa(objReceive.Name);
					else if (objReceive.event == "khongdilai")
						ProcessInTable.Other_KhongDilai(objReceive.Name);
				}
			} else if (objReceive.evt == "codilai") {
				if (Cocaro.mainStage_mc.currentFrame == 5)
					ProcessInTable.Dilai(objReceive.Name) ;				
			} else if (objReceive.evt == "finishgame") {
				if (Cocaro.mainStage_mc.currentFrame == 5) 
					ProcessInTable.FinishedGame(objReceive.data) ;
			} else if (objReceive.evt == "thongbao") {
				BasicFunction.ShowAlert(objReceive.Cmd);
			} /*else if (objReceive.evt == "chattable") {
				if (Cocaro.mainStage_mc.currentFrame == 5)
					Cocaro.Chat(objReceive) ;
			}*/ else if (objReceive.evt == "am") {
				var o:Object = new Object();
				o.Name = objReceive.N;
				o.Mark = objReceive.M;
				if (Cocaro.mainStage_mc.currentFrame == 5) 
					ProcessInTable.UpdateMoney_InTable(objReceive) ;
				//ProcessInTable.UpdateMoney(JSON.encode(o));
			} else if (objReceive.evt == "0") {
				BasicFunction.ShowAlert(objReceive.data);
			} else if (objReceive.evt == "chattable") {
				if (Cocaro.mainStage_mc.currentFrame == 5) {
					if (objReceive.T == null)
						ChatFunction.Chat(objReceive) ;
					else 
						EmotionFunction.Display_Emotion_Control(objReceive) ;
				}
			} else if (objReceive.evt == "schat") {
				if (Cocaro.mainStage_mc.currentFrame == 5) {
					ChatFunction.Chat(JSON.decode(objReceive.data)) ;					
				}
			} else if (objReceive.evt == "setting") {
				if (Cocaro.mainStage_mc.currentFrame == 5)
					ProcessInTable.Setting(JSON.decode(objReceive.data)) ;
			}
			//
			//var dec:Array = (JSON.decode(msg) as Array)
			//var className:String = dec[0];
			//if (!className.match("State"))
			//{
				//return;
			//}				
			//var pits:Object = dec[1];
			//chooseSide(pits.southPlayerId, pits.northPlayerId);
			//updateBoard(pits.pits);
		}

		public function handleCreateTableResponsePacket(handle:CreateTableResponsePacket):void {
			if (handle.code == 1) {
				BasicFunction.ShowAlert("Bạn không đủ điểm tạo bàn. Vui lòng nạp thêm AG để bá đạo...");
			} else {
				Cocaro.tableID = handle.tableid;
				//Cocaro.tf.appendText("ctable:"+handle.tableid);
				//sendJoinTableRequest(Cocaro.tableID);
			}
		}
		
		function onTableAdded(lobbyEvent:LobbyEvent):void {
			var lobbyDataItem:LobbyDataItem = lobbyEvent.lobbyDataItem;
			var item:Object = new Object();
			try {
				if (lobbyDataItem.getValue("N") != null &&
					lobbyDataItem.getValue("M") != null &&
					lobbyDataItem.getValue("ArrN") != null) {
					item.Id = lobbyDataItem.tableid;
					item.Name = lobbyDataItem.getValue("N");
					item.MarkUnit = lobbyDataItem.getValue("M");
					item.RId = Cocaro.roomID;
					item.ArrName = JSON.decode(lobbyDataItem.getValue("ArrN"));
					Cocaro.isKickRoom = true ;
					if (Cocaro.mainStage_mc.currentFrame == 4)
						ProcessOutTable_Frame2.initTable(item);
				}
			}catch (e:Error) {
			}
		}

		function onTableUpdated(lobbyEvent:LobbyEvent):void {
			var lobbyDataItem:LobbyDataItem = lobbyEvent.lobbyDataItem;
			//var item:Object = new Object();
			try {
				//Cocaro.tf.appendText("ArrNameNew : " + lobbyDataItem.getParameterNames.length);
				//Cocaro.tf.appendText("ArrNameNew : " + lobbyDataItem.getValue("ArrName"));
				//if (lobbyDataItem.getValue("Name") != null &&
					//lobbyDataItem.getValue("MarkUnit") != null &&
					//lobbyDataItem.getValue("RId") != null &&
					//lobbyDataItem.getValue("ArrName") != null) {
						//item.Id = lobbyDataItem.tableid;
						//item.Name = lobbyDataItem.getValue("Name");
						//item.MarkUnit = lobbyDataItem.getValue("MarkUnit");
						//item.RId = lobbyDataItem.getValue("RId");
						//item.ArrName = JSON.decode(lobbyDataItem.getValue("ArrName"));
						//Cocaro.isKickRoom = true ;
						//if (Cocaro.mainStage_mc.currentFrame == 4)
							//Cocaro.initTable(item);
					//}
			}catch (e:Error) { }
		}

		function onTableRemoved(lobbyEvent:LobbyEvent):void {
			//Cocaro.tf.appendText("Table removed");
			// find table and remove it from the list
			//for each ( var item:Object in lobbyData ) { 
				//if ( item.tableId == lobbyEvent.tableId ) {
					//lobbyData.splice(lobbyData.indexOf(item),1);
					//break;
				//}
			//}
		}
		
		/*
		 * evt :
			 * 1 = addlevel
			 * 2 = addroom
			 * 3 = addtable
			 * 4 = Gửi tạo bàn mới và nhận được id của bàn giờ gửi thông tin join bàn này.
			 * 5 = Thông báo tặng tiền nhưng không add.
			 * 7 = Thông báo tặng tiền nhưng add.
			 * 8 = Receive AG Trans
			 * 9 = add item table.
			 * 
		 */
		private function handleServiceTransportPacket(serviceTransportPacket:ServiceTransportPacket):void
		{
			var data:ByteArray = serviceTransportPacket.servicedata;
			var bytes:int = data.bytesAvailable;
			var msg:String = data.readUTFBytes(bytes);				
			var decoded:Object = JSON.decode(msg);
			//if (decoded.evt == "chuyentien") {
				//Cocaro.ResultTransferAG(decoded.Cmd);
			//} else if (decoded.evt == "thongbao") {
				//BasicFunction.ShowAlert(decoded.Cmd);
			//}  
			if (decoded.evt == "13") { //Thong bao chuyen tien thanh cong
				BankFunction.ResultTransferAG(decoded.Cmd);
			} else if (decoded.evt == "10") {
				BasicFunction.ShowAlert(decoded.Cmd) ;				
			} else if (decoded.evt == "0") {
				//Cocaro.tf.appendText("user=>"+decoded.data);
				var obj:Object = JSON.decode(decoded.data);
				Cocaro.currPlayer.PlayerName = obj.Username;
				Cocaro.currPlayer.Mark = obj.AG;
				Cocaro.currPlayer.MarkLQ = obj.LQ;
				Cocaro.currPlayer.VIP = obj.VIP ;
				Cocaro.currPlayer.LoanAG = obj.AGVay ;
				Cocaro.currPlayer.TotalGames = obj.W + obj.L;
				Cocaro.currPlayer.WinGames = obj.W ;
				Cocaro.currPlayer.TinyURL = obj.Tinyurl;
				Cocaro.currPlayer.CountMsg = obj.CMsg;
				Cocaro.currPlayer.X = obj.X;
				Cocaro.currPlayer.LoanAG = obj.AGVay ;
				Cocaro.currPlayer.Lock = obj.Pass ;				
				Cocaro.currPlayer.ArrChess = new Array();
				Cocaro.currPlayer.ArrChess_Movie = new Array();
				Cocaro.mainStage_mc.gotoAndStop(2);				
			} else if (decoded.evt == "1") {
				ProcessOutTable_Frame1.initLevelRoom(decoded.data);
				var promote:Object = new Object();
				promote.evt = "7";
				sendService(JSON.encode(promote));
			} else if (decoded.evt == "2") {
				ProcessOutTable_Frame2.initRoom(decoded.data);
			} else if (decoded.evt == "3") {
				//registryLobby();
				addLobby();
				//Cocaro.tf.appendText("=>registry lobby=>");
				Cocaro.isKickRoom = true ;
				if (Cocaro.mainStage_mc.currentFrame == 4)
					ProcessOutTable_Frame2.initTable(JSON.decode(decoded.data));
			} else if (decoded.evt == "4") {
				//Cocaro.tf.appendText(decoded.tableid);
				if (decoded.tableid == 0) {
					var tmpTB:MovieClip = MovieClip(new Popup_TangAG()) ;
					if (Cocaro.currPlayer.X == 1)
						tmpTB.txtThongbao.text = "Bạn không đủ điểm để tạo bàn chơi. Bạn được tặng 1 thẻ X2 (nhân đôi giá trị thẻ nạp đầu tiên trong ngày hôm nay). Bạn muốn chơi tiếp hay nạp thêm AG?" ;
					else 
						tmpTB.txtThongbao.text = "Bạn không đủ điểm để tạo bàn chơi, Bạn có muốn nạp thêm AG ?"	 ;
					tmpTB.NapAG_btn.addEventListener(MouseEvent.CLICK, Cocaro.NapAG_Popup_Click) ;
					tmpTB.Choitiep_btn.addEventListener(MouseEvent.CLICK, Cocaro.Choitiep_Popup_Click) ;
					tmpTB.name = "TangAG" ;
					tmpTB.x = 0;
					tmpTB.y = 0;
					Cocaro.mainStage_mc.addChild(tmpTB) ;
					//BasicFunction.ShowAlert("Bạn không đủ điểm để tạo bàn chơi !");
				} else
					sendJoinTableRequest(decoded.tableid);
			} else if (decoded.evt == "ff") {
				if (decoded.data == "0")
					BasicFunction.ShowAlert("Hết bàn trống, mời bạn tạo bàn chơi.") ;
				else 
					sendJoinTableRequest(parseInt(decoded.data));
			}  else if (decoded.evt == "5") {
				BasicFunction.ShowAlert("Bạn được tặng " + decoded.data + " AG.");
			} else if (decoded.evt == "7") {
				ProcessInTable.UpdateMoney(parseInt(decoded.data));
				//var o:Object = new Object();
				//o.Name = Cocaro.currPlayer.PlayerName;
				//o.Mark = parseInt(decoded.data);
				//Cocaro.UpdateMoney(JSON.encode(o));
			} else if (decoded.evt == "8") {
				//Cocaro.DisplayHistory(decoded.data) ;
			} else if (decoded.evt == "9") {
				var item:Object = new Object();
				var s:String = decoded.data;
				var dt:Object = JSON.decode(s);
				item.Id = dt.Id;
				item.Name = dt.Name;
				item.MarkUnit = dt.MarkUnit;
				item.RId = dt.RId;
				item.ArrName = JSON.decode(dt.ArrName);
				Cocaro.isKickRoom = true ;
				if (Cocaro.mainStage_mc.currentFrame == 4)
					ProcessOutTable_Frame2.initTable(item);
			} else if (decoded.evt == "11") { //Friend Follow
				if (decoded.T == 1)
					FriendFunction.ReceiveFriendGame(decoded.Arr) ;				
			} else if (decoded.evt == "16") {
				ChatFunction.ChatOutTable(decoded) ;				
			} else if ((decoded.evt == "15") && (decoded.T = 10)) {
				MailFunction.NewMail() ;				
			} else if (decoded.evt == "20") { //Mail Admin
				//AS3Cay.tf.appendText("==>Page:" + decoded.P) ;
				MailFunction.totalPageAdmin = decoded.P ;
				MailFunction.MailAdmin(decoded.data) ;
			} else if (decoded.evt == "21") { //Mail Player				
				MailFunction.totalPagePlayer = decoded.P ;
				MailFunction.MailPlayer(decoded.data) ;
			} else if (decoded.evt == "22") { //Mail Transfer
				MailFunction.totalPageTransfer = decoded.P ;
				MailFunction.MailTransfer(decoded.data) ;
			} else if (decoded.evt == "31") { //Receive AG, Item
				MailFunction.ReceiveAG(decoded) ;
			} else if (decoded.evt == "cv") {
				LQAGFunction.LQAGConvert(decoded) ;
			} else if ((decoded.evt == "14") && (decoded.T == "1")) {
				BankFunction.ResultLoanAG(decoded.data) ;				
			} else if ((decoded.evt == "14") && (decoded.T == "2")) {
				BankFunction.ResultPayAG() ;
			} else if ((decoded.evt == "12") && (decoded.T == "7")) {
				LockFunction.DeleteLockOK() ;
			} else if ((decoded.evt == "12") && (decoded.T == "5")) {
				LockFunction.UnLockOK() ;
			} else if ((decoded.evt == "12") && (decoded.T == "2")) {
				LockFunction.UnLockWaitOK() ;
			} else if ((decoded.evt == "12") && (decoded.T == "1")) {
				LockFunction.CreateLockOK() ;
			} else if (decoded.evt == "dg") {
				AuctionFunction.AuctionOK(decoded) ;
			} else if (decoded.evt == "pf") {
				ProfileFunction.Profile_OK() ;
			} else if (decoded.evt == "time") {
				LuckyCardFunction.DisplayData(decoded) ;
			} else if (decoded.evt == "slucky") {
				LuckyCardFunction.Result(decoded) ;
			} else if (decoded.evt == "flucky") {
				LuckyCardFunction.LuckyAG(decoded) ;
			} else if (decoded.evt == "cvd") {
				OtherFunction.ConvertGoldOK(decoded) ;
			} else if (decoded.evt == "100") {
				OtherFunction.SpecialAlert(decoded.Cmd) ;
			}
		}
		
		public function sendJoinTableRequest(id:int):void {
			//if (Cocaro.tableID != 0) return;
			var joinRequestPacket:JoinRequestPacket = new JoinRequestPacket();
			joinRequestPacket.seat = -1;
			joinRequestPacket.tableid = id;
			//if(Cocaro.PARAM_CREATE_TABLE.length > 0)
				//joinRequestPacket.params = Cocaro.PARAM_CREATE_TABLE;
			//Cocaro.tf.appendText("=>joinrequest : "+ id);
			send(joinRequestPacket); 
		}
		private function handleJoinResponsePacket(joinResponsePacket:JoinResponsePacket):void
		{
			if(joinResponsePacket.code == 0)
				Cocaro.tableID = joinResponsePacket.tableid;
			else if (joinResponsePacket.code == -1)
				BasicFunction.ShowAlert("Bàn đã hết chỗ trống. Bạn vui lòng chọn bàn khác !");
			else if (joinResponsePacket.code == -2)
				BasicFunction.ShowAlert("Bàn đã hủy. Bạn vui lòng chọn bàn khác !");
			else if (joinResponsePacket.code == -3)
				BasicFunction.ShowAlert("Bạn không đủ điểm để tham gia bàn chơi !");
			else if (joinResponsePacket.code == -4)
				BasicFunction.ShowAlert("Bạn đang ở trong bàn chơi");
			else if (joinResponsePacket.code == -5)
				BasicFunction.ShowAlert("Bàn đã bắt đầu ván !");
		}
		
		public function registryLobby() {
			Cocaro.oldaddressLobby = Cocaro.newaddressLobby;
			Cocaro.newaddressLobby = Cocaro.levelID + "/" + Cocaro.roomID + "/";
			if(Cocaro.oldaddressLobby.length > 0 )
				unRegistryLobby();
			var obj:Object = new Object();
			obj.gameid = Cocaro.GAME_ID;
			//obj.lobby = lobby;
			obj.evt = "5";
			//sendService(JSON.encode(obj));
		}
		
		public function unRegistryLobby() {
			var obj:Object = new Object();
			obj.gameid = Cocaro.GAME_ID;
			obj.evt = "6";
			//sendService(JSON.encode(obj));
		}
	}
}